package com.zhouyu;

import com.zhouyu.mapper.OrderMapper;
import com.zhouyu.mapper.UserMapper;
import com.zhouyu.service.UserService;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class Test {


	public static void main(String[] args) {
		AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
		applicationContext.register(AppConfig.class);

		//(1)直接在代码层，注册需要的BeanDefinition
//		AbstractBeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition().getBeanDefinition();
//		beanDefinition.setBeanClass(ZhouyuFactoryBean.class);
//		beanDefinition.getConstructorArgumentValues().addGenericArgumentValue(UserMapper.class);
//		applicationContext.registerBeanDefinition("userMapper",beanDefinition);
//
//		AbstractBeanDefinition beanDefinition2 = BeanDefinitionBuilder.genericBeanDefinition().getBeanDefinition();
//		beanDefinition2.setBeanClass(ZhouyuFactoryBean.class);
//		beanDefinition2.getConstructorArgumentValues().addGenericArgumentValue(OrderMapper.class);
//		applicationContext.registerBeanDefinition("orderMapper",beanDefinition2);


		applicationContext.refresh();

		UserService userService = (UserService) applicationContext.getBean("userService");
		userService.test();
	}
}







